package com.kfyang.manualgear.util;

import com.kfyang.manualgear.struct.Handler;
import com.kfyang.manualgear.struct.MethodInfo;
import com.kfyang.manualgear.struct.ParameterInfo;
import com.kfyang.manualgear.struct.ReturnTypeInfo;

import javax.annotation.processing.Filer;
import javax.annotation.processing.Messager;
import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import java.util.*;

import static com.kfyang.manualgear.constant.ClassConstants.*;
import static com.kfyang.manualgear.constant.MethodConstants.*;
import static com.kfyang.manualgear.constant.TypeNameConstants.*;
import static com.kfyang.manualgear.util.CheckUtils.checkNotNull;

/**
 * 全局对象
 */
public final class GlobalConfigUtils {
    /**
     * 要复制的注解
     */
    public static Set<String> copyAnnotations = new HashSet<>();

    /**
     * Object 类对应元素
     */
    public static Element objectElement;
    public static Types typeUtils;
    public static Elements elementUtils;
    public static Filer filer;
    public static Messager messager;

    public static Handler getTypeHandler(String type) {
        Handler handler = typeToHandlerMap.get(type);
        checkNotNull(handler, type + "没有对应的类型处理器");
        return handler;
    }

    /**
     * 方法信息表
     */
    public static final Map<String, List<MethodInfo>> methodInfoMap = new HashMap<>();
    /**
     * 类型到处理器的哈希表
     */
    public static final Map<String, Handler> typeToHandlerMap = new HashMap<>();
    public static final Map<String, ReturnTypeInfo> returnTypeMap = new HashMap<>();

    /**
     * 从返回类型到字段名到处理器
     */
    public static final Map<TypeElement, Map<String, Handler>> fieldToHandlerMaps = new HashMap<>();

    /**
     * 从实体类到构造器 id 到构造器参数列表
     */
    public static final Map<TypeElement, Map<String, List<ParameterInfo>>> constructorMaps = new HashMap<>();

    /**
     * 列名别名
     */
    public static final String[] alias = {"c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "c10",
        "c11", "c12", "c13", "c14", "c15", "c16", "c17", "c18"};

    /**
     * 可以直接生成的简单方法
     */
    public static final Set<String> methodSet = Set.of(
        SELECT_BY_ID, SELECT_ALL,
        INSERT, INSERT_ALL,
        UPDATE,
        DELETE_BY_ID, DELETE_BY_IDS
    );

    /**
     * 打印横幅
     */
    public static void printBanner() {
        System.out.println(
                "   ____    ______                   \n" +
                " .' __ \\  |_   _ `.                 \n" +
                "/ .'  \\ |   | | `. \\ ,--.    .--.   \n" +
                "| | (_/ |   | |  | |`'_\\ : / .'`\\ \\ \n" +
                "\\ `.__.'\\  _| |_.' /// | |,| \\__. | \n" +
                " `.___ .' |______.' \\'-;__/ '.__.'  \n" +
                "                              0.1.0"
        );
    }
}
